<template>
  <view class="login_container">
    <uni-icons type="contact-filled" size="150" color="#999"></uni-icons>
    <button  @click="getUserProfile">一键登录</button>
    <text>登录享受更多权益</text>
  </view>
</template>

<script>
  export default {
    name:"Mylogin",
    data() {
      return {
        
      };
    },
    methods:{
      getUserProfile(e){
         uni.getUserProfile({
                  desc: '你的授权信息',
                  success: (res) => {
                    // 将信息存到 vuex 中
                    this.$store.commit('userStore/saveUserInfo',res.userInfo),                            this.$store.commit('userStore/saveToken','renjdsanwnrowpiqneqnkdsnaldnqwneqwpinepq') 
                    this.login(res)
                  },
                  fail: (res) => {
                    return uni.$showMsg('您取消了登录授权')
                  }
                })
        
      },
      async login(info){
        let [err,res]=await uni.login()
        if(err!==null) return uni.$showMsg('登录出错')
         const query = {
             code: res.code,
             encryptedData: info.encryptedData,
             iv: info.iv,
             rawData: info.rawData,
             signature: info.signature
           }
        
      }
    }
  }
</script>

<style lang="scss">
  .login_container{
    display: flex;
    align-items: center;
    flex-direction: column;
   uni-icons{
     margin-top: 120px;
   }
    button{
      height: 50px;
      width: 90%;
      background-color: #c00000;
      color: #fff;
      border-radius: 30px;
      display: flex;
      font-size: 20px;
      justify-content: center;
      align-items: center;
    }
    .button-hover[type=primary]{
      background-color: #b00000;
    }
    text{
      margin-top: 10px;
      font-size: 14px;
      color: #999;
    }
  }

</style>